"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTagBlog = exports.getTypeBlog = exports.updateBlog = exports.getDetail = exports.delblog = exports.getDataTotal = exports.readBlogdata = exports.addblogData = void 0;
const sqlTool_1 = require("../tool/sqlTool");
// 保存博客
function addblogData(blog) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`insert into blogs (uid,title,introduction,content,blog_type,img,blog_tag,read_,create_time,blog_id,author) 
    values (?,?,?,?,?,?,?,?,now(),uuid(),?) `, [
            blog.uid,
            blog.title,
            blog.introduction,
            blog.content,
            blog.blog_type,
            blog.img,
            blog.blog_tag,
            blog.read_,
            blog.author,
        ]);
    });
}
exports.addblogData = addblogData;
//读取博客
function readBlogdata(page) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`select * from blogs order by create_time  Asc limit ${(page - 1) * 10},10`, []);
    });
}
exports.readBlogdata = readBlogdata;
// 查询数据总条数
function getDataTotal() {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`select count(*) as total from blogs`, []);
    });
}
exports.getDataTotal = getDataTotal;
// 删除博客
function delblog(id) {
    return __awaiter(this, void 0, void 0, function* () {
        console.log(id);
        return (0, sqlTool_1.dosql)(`delete from blogs where id=${id} `, []);
    });
}
exports.delblog = delblog;
// 删除博客
function getDetail(id) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(` select * from blogs where id=${id} `, []);
    });
}
exports.getDetail = getDetail;
// 更新博客
function updateBlog(blog) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`update blogs set title=?,introduction=?,content=?,blog_type=?,img=?,blog_tag=?,read_=? where id=?`, [
            blog.title,
            blog.introduction,
            blog.content,
            blog.blog_type,
            blog.img,
            blog.blog_tag,
            blog.read_,
            blog.id,
        ]);
    });
}
exports.updateBlog = updateBlog;
function getTypeBlog(id) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`select * from blogs where blog_type=${id}`, []);
    });
}
exports.getTypeBlog = getTypeBlog;
function getTagBlog(id) {
    return __awaiter(this, void 0, void 0, function* () {
        return (0, sqlTool_1.dosql)(`select * from blogs where blog_tag=${id}`, []);
    });
}
exports.getTagBlog = getTagBlog;
